package cn.mesmile.flow.config.listen;

import cn.hutool.core.date.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.flowable.common.engine.api.delegate.event.FlowableEngineEntityEvent;
import org.flowable.engine.delegate.event.AbstractFlowableEngineEventListener;
import org.flowable.engine.delegate.event.BaseEntityEventListener;
import org.flowable.engine.delegate.event.FlowableProcessStartedEvent;
import org.springframework.stereotype.Component;

/**
 * @author zb
 * @date 2020/12/25 13:56
 * @Description
 */
@Slf4j
@Component
public class GlobalProcessListener extends AbstractFlowableEngineEventListener {

    /**
     * {@link BaseEntityEventListener}
     *
     * org.flowable.engine.delegate.event.BaseEntityEventListener: 事件监听器基类，
     * 可用来监听实体（entity）相关事件，特定或所有实体的事件都可以。它隐藏了类型检测，
     * 提供了4个需要覆盖的方法：onCreate(..), onUpdate(..)与onDelete(..)在实体创建、更新及删除时调用；
     * 对所有其他实体相关事件，onEntityEvent(..)会被调用。
     *
     */

    @Override
    protected void processCreated(FlowableEngineEntityEvent event) {
        log.info(">>>>>>>>>>>>>>>>>>>>>>>>>> 进入流程实例【创建】，{}", DateUtil.now());
    }

    @Override
    protected void processStarted(FlowableProcessStartedEvent event) {
        log.info(">>>>>>>>>>>>>>>>>>>>>>>>>> 进入流程实例【开始】，{}", DateUtil.now());
    }

    @Override
    protected void processCompleted(FlowableEngineEntityEvent event) {
        log.info(">>>>>>>>>>>>>>>>>>>>>>>>>  进入流程实例【完成】，{}", DateUtil.now());
    }


}
